package wef.PW.module.analysis;

import wef.PW.module.model.APDU;
import wef.PW.module.model.ASDU;
import wef.PW.utils.ASDUUtils;
import wef.PW.utils.StrUtils;

public class RewardSplitImpl implements RewardSplit {

    private RewardSort rewardSort;
    public void classify(String reward) {
        String UDID = reward.substring(0, 2);
        if (!UDID.equals("68")){
            System.out.print("非正确的报文格式！");
        }else {
            //储存报文
            APDU message = new APDU();
            message.setUDID(UDID);
            String APDUL = reward.substring(2, 4);
            message.setAPDUL(APDUL);
            message.setCLDN1(reward.substring(4, 6));
            message.setCLDN2(reward.substring(6, 8));
            message.setCLDN3(reward.substring(8, 10));
            message.setCLDN4(reward.substring(10, 12));
            if (StrUtils.hexStrToInt(APDUL) > 4){ // 报文长度 > 4 时为 I 格式报文 有应用服务单元数据
                //调用ASDUUtils.APDUSToObject()解析应用服务单元数据(ASDU)字符串
                ASDU asdu = ASDUUtils.APDUSToObject(reward.substring(12, reward.length()));
                message.setAsdu(asdu);
            }
            System.out.println(message);
            new RewardSortImpl(message);
        }
    }
}
